<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>ES6标准</title>
  </head>
  <body>
    <h2>变量的解构赋值</h2>
    <script>
      /*
        //1. 数组的解构赋值
        let [a,b,c] = [10,20,30];
        console.log(a);
        console.log(b);
        console.log(c);
        */

      /*
        //解构部分数值
        let [x ,, y] = [10, 20 , 30];
        console.log(x);
        console.log(y);
        let [x1, x2,...xn] = [10,20,30,40,50];
        console.log(x1);
        console.log(x2);
        console.log(xn);
        //默认值
        let [a, b=0] = [10];
        console.log(a);
        console.log(b);
        */

      //2. 对象的解构赋值
      //let {name, sex, age} = {name:'张三', age:20, sex:'男'};
      //let {age, sex, name} = {name:'张三', age:20, sex:'男'};
      //部分解构
      //let {age, name} = {name:'张三', age:20, sex:'男'};
      //解构对象起别名和默认值
      // console.log(name);
      // console.log(age);
      // console.log(sex);
      //解构对象起别名和默认值
      // let {age:a,name:b,id=100} = {name:'张三', age:20, sex:'男'};
      // console.log(a);
      // console.log(b);
      // console.log(id);
      //复杂对象解构
      //定义一个书的信息
      // var obj = {
      //     book: [
      //         'JavaScript权威指南',
      //         {author:'小陶',price:69}
      //     ]
      // };
      // let {book:[title,{author,price}]} = obj;
      // let {book, book:[title, {author,price}]} = obj;
      // console.log(title, author, price);
      // console.log(book);

      //3. 字符串解构赋值
      // const [a, b, c, d, e] = 'hello';
      // console.log(a);
      // console.log(b);
      // console.log(c);
      // console.log(d);
      // console.log(e);
    </script>
  </body>
</html>
